#GLOBAL
uniform float simulateSize;
uniform vec2 sampleOffsets[8];
uniform sampler2D MyTexture;
#END

#VS
attribute vec3 Position0;
attribute vec2 Texcoord0;

out vec4 Position_VSPS;
out vec2 Texcoord_VSPS;

void main()
{
	gl_Position = Position_VSPS = vec4(Position0, 1);




	Texcoord_VSPS = Texcoord0;

}
#END

#PS
in vec4 Position_VSPS;
in vec2 Texcoord_VSPS;

out vec4 glFragColorOut[1];

void main()
{
	vec4 color = texture2D(MyTexture, Texcoord_VSPS);
	color = (color-0.5) * 2.0;

	vec3 normal = vec3(0, 0, 0);
	for (int i = 0; i != 8; ++i)
	{
		vec2 offset = sampleOffsets[i];
		vec4 block = texture2D(MyTexture, Texcoord_VSPS + (offset * simulateSize));
		block = (block-0.5) * 2.0;

		vec3 vec = vec3(offset, block.z-color.z);
		vec3 up = vec3(0, 0, 1);

		up = cross(vec, up);
		normal += cross(vec, up);
	}
	normal = -normalize(normal);
	glFragColorOut[0] = vec4((normal+1.0) * 0.5, 1);
}
#END

